#!/usr/bin/env python3

import os
from datetime import datetime, timezone

REBOOT_CAUSE_DIR = "/host/reboot-cause/"
REBOOT_LC_BY_SUPERVISOR_FILE = os.path.join(REBOOT_CAUSE_DIR, "reboot-lc-by-supervisor.txt")

def main():
    reboot_time = datetime.now(timezone.utc).strftime("%a %b %d %I:%M:%S %p %Z %Y")

    if os.path.exists(REBOOT_LC_BY_SUPERVISOR_FILE):
        os.remove(REBOOT_LC_BY_SUPERVISOR_FILE)
        with open(os.path.join(REBOOT_CAUSE_DIR, "reboot-cause.txt"), 'w') as reboot_cause_file:
            reboot_msg = "User issued 'Reboot from Supervisor' command [User: Supervisor, Time: {}]".format(reboot_time)
            reboot_cause_file.write(reboot_msg)

if __name__ == "__main__":
    main()
